\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{graphicx} 
\usepackage{float}
\usepackage[left=1cm,right=1cm,top=1cm,bottom=2cm]{geometry}
\title{NumPDE Homework 7}
\author{Jiang Zhou 3220101339}
\date{2025/5/18}

\begin{document}
\maketitle
\section{Exercise 12.11}
The Crank-Nicolson method solves the heat equation (12.3) by
\begin{equation*}
    \frac{U_i^{n+1} - U_i^n}{k} = \frac{v}{2h^2}(U_{i-1}^n-2U_i^n+U_{i+1}^n+U_{i-1}^{n+1}-2U_i^{n+1} + U_{i+1}^{n+1}).
\end{equation*}
We can rewrite this as:
\begin{equation}
    \label{eq1}
    U_i^{n+1} - \frac{r}{2}(U_{i-1}^{n+1}-2U_i^{n+1} + U_{i+1}^{n+1}) = U_i^n + \frac{r}{2}(U_{i-1}^n-2U_i^n+U_{i+1}^n).
\end{equation}
For $i=1$ and $i=m$, the equations involve boundary values:

\begin{align*}
\text{For } i=1: & \quad  U_1^{n+1} - \frac{r}{2}(U_{0}^{n+1}-2U_1^{n+1} + U_{2}^{n+1}) = U_1^n + \frac{r}{2}(U_{0}^n-2U_1^n+U_{2}^n)\\
\text{For } i=m: & \quad  U_m^{n+1} - \frac{r}{2}(U_{m-1}^{n+1}-2U_m^{n+1} + U_{m+1}^{n+1}) = U_m^n + \frac{r}{2}(U_{m-1}^n-2U_m^n+U_{m+1}^n)
\end{align*}
We can rewrite this as:
\begin{align}
    \label{eq2}
\text{For } i=1: & \quad  U_1^{n+1} - \frac{r}{2}(-2U_1^{n+1} + U_{2}^{n+1}) = U_1^n + \frac{r}{2}(-2U_1^n+U_{2}^n) + \frac{r}{2}(g_0(t_{n+1})+g_0(t_n))\\
    \label{eq3}
\text{For } i=m: & \quad  U_m^{n+1} - \frac{r}{2}(U_{m-1}^{n+1}-2U_m^{n+1}) = U_m^n + \frac{r}{2}(U_{m-1}^n-2U_m^n) + \frac{r}{2}(g_1(t_{n+1}) + g_1(t_n))
\end{align}
where $g_0$ and $g_1$ are the Dirichlet boundary conditions at the left and right endpoints respectively.\\

Combining these equations\ref{eq1}, \ref{eq2} and \ref{eq3}, we can get:
\begin{align*}
\text{For } i=1: & \quad  U_1^{n+1} - \frac{r}{2}(-2U_1^{n+1} + U_{2}^{n+1}) = U_1^n + \frac{r}{2}(-2U_1^n+U_{2}^n) + \frac{r}{2}(g_0(t_{n+1})+g_0(t_n))\\
\text{For } i=2, 3 \ldots m-1: & \quad U_i^{n+1} - \frac{r}{2}(U_{i-1}^{n+1}-2U_i^{n+1} + U_{i+1}^{n+1}) = U_i^n + \frac{r}{2}(U_{i-1}^n-2U_i^n+U_{i+1}^n)\\
\text{For } i=m: & \quad  U_m^{n+1} - \frac{r}{2}(U_{m-1}^{n+1}-2U_m^{n+1}) = U_m^n + \frac{r}{2}(U_{m-1}^n-2U_m^n) + \frac{r}{2}(g_1(t_{n+1}) + g_1(t_n)).
\end{align*}
Thus, we have shown the matrix form of the Crank-Nicolson method is:

\begin{equation*}
\left(I - \frac{k}{2}A\right)\mathbf{U}^{n+1} = \left(I + \frac{k}{2}A\right)\mathbf{U}^n + \mathbf{b}^n
\end{equation*}
where \begin{equation*}
\mathbf{b}^n = \frac{r}{2}
\begin{bmatrix}
g_0(t_n) + g_0(t_{n+1}) \\
0 \\
\vdots \\
0 \\
g_1(t_n) + g_1(t_{n+1})
\end{bmatrix}
\end{equation*}
\section{Exercise 12.26}
Consider the $\theta$-method applied to the heat equation $u_t = \nu u_{xx}$:

\begin{equation*}
\frac{U^{n+1}_i - U^n_i}{k} = \frac{\nu}{h^2}\left[\theta (U^{n+1}_{i-1} - 2U^{n+1}_i + U^{n+1}_{i+1}) + (1-\theta)(U^n_{i-1} - 2U^n_i + U^n_{i+1})\right]
\end{equation*}
which can be rewriten as:
\begin{align}
    \left(I - k\theta A\right)\mathbf{U}^{n+1} = \left(I + k(1-\theta) A\right)\mathbf{U}^n + \mathbf{b}^n
\end{align}
As a result, the stability function is given by:
\begin{align*}
    R(z) = \frac{1+(1-\theta) z}{1-\theta z}, \quad z = k\lambda
\end{align*}
\subsection{If \(\theta \in [\frac{1}{2}, 1]\)}
Since $\lambda$ is a negative real number, we can get $z = k\lambda$ is also a negative real number. Thus, we can get:
\[
|R(z)|^2 = |\frac{1+(1-\theta) z}{1-\theta z}|^2 = \frac{1-2\theta z + \theta^2 z^2 + 2z + (1-2\theta)z^2}{1-2\theta z + \theta^2z^2}
\]
Because $z$ is a negative real number and \(\theta \in [\frac{1}{2}, 1]\), we can get \(2z + (1-2\theta)z^2 <0\), which yeilds:
\[
|R(z)|^2 < 1, \forall z = k\lambda.
\]
By Lemma 12.24, the $\theta$-method is unconditionally stable for \(\theta \in [\frac{1}{2}, 1]\).
\subsection{If \(\theta \in [0, \frac{1}{2})\)}
In order to get \(2z + (1-2\theta)z^2 \leq 0\), we can get:
\[
-\frac{2}{1-2\theta} \leq z < 0
\]
Due to the fact that \(z = k\lambda\) is a negative real number, we can get:
\[
    k\leq -\frac{2}{(1-2\theta)\lambda}
\]
From the (12.25), we know that: \(\lambda_{min} = -\frac{4\nu}{h^2}\).
As a result, we can get:
\[
    k\leq -\frac{2}{(1-2\theta)\lambda_{min}} = \frac{h^2}{4\nu}*\frac{2}{(1-2\theta)} = \frac{h^2}{2\nu(1-2\theta)}
\]
\section{12.3.1}
\subsection{(a) Comparison of Numerical Methods for Heat Equation}
\begin{figure}[H]
    \centering
    \includegraphics[width=0.5\textwidth]{figure/a.png}
    \caption{Comparison of Numerical Methods for Heat Equation}
    \label{fig:a}
\end{figure}
\subsubsection{Exact Solution}
\begin{itemize}
    \item The exact solution shows smooth diffusion over time, with the initial peak gradually flattening while maintaining non-negativity.
    \item The solution decays uniformly, respecting the maximum principle (the maximum value decreases over time).
\end{itemize}

\subsubsection{Crank-Nicolson (CN) Method}
CN with \( r = 1 \):
\begin{itemize}
    \item Accuracy: Matches the exact solution closely.
    \item The solution decays uniformly, respecting the maximum principle (the maximum value decreases over time).
\end{itemize}
CN with \( r = 2 \):
Introduces slight oscillations at \(t=k\), violating the discrete maximum principle (negative values appear).

\subsubsection{Backward-Time Centered-Space (BTCS)}
\begin{itemize}
    \item Accuracy: Matches the exact solution reasonably well.
    \item Stability: No oscillations, preserving the maximum principle.
\end{itemize}

\subsubsection{Collocation Method (Example 11.96)}
\begin{itemize}
    \item Accuracy:  Matches the exact solution reasonably best.
    \item Stability: No oscillations, preserving the maximum principle.
\end{itemize}

\subsection{(b) Comparison of BTCS and Collocation Methods for Heat Equation}
\begin{figure}[H]
    \centering
    \includegraphics[width=0.5\textwidth]{figure/b.png}
    \caption{Comparison of BTCS and Collocation Methods for Heat Equation}
    \label{fig:b}
\end{figure}
For BTCS: Unconditional stability. The image should show no oscillation, even at large time steps and respect the maximum principle \\
For Collocation: Non-physical oscillation (especially where the initial conditions are steep).

\subsection{(c) FTCS for Heat Equation}
\begin{figure}[H]
    \centering
    \includegraphics[width=0.5\textwidth]{figure/c.png}
    \caption{FTCS for Heat Equation}
    \label{fig:c}
\end{figure}
\begin{itemize}
    \item Severe Oscillations: The numerical solution exhibits high-frequency oscillations, violating the physical behavior of the heat equation.
    \item Violation of Maximum Principle: The solution develops unphysical negative values, indicating instability.
    \item Amplification of Errors: Oscillations grow with time, making the solution unreliable.
\end{itemize}



\subsection{(d)G-L RK method for Heat Equation}
\begin{figure}[H]
    \centering
    \includegraphics[width=0.5\textwidth]{figure/d.png}
    \caption{G-L RK method for Heat Equation}
    \label{fig:d}
\end{figure}
For \(r = \frac{1}{2h}\), the numerical solution exhibits oscillations and exists negative values,  violating the Maximum Principle.
\end{document}
